﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


#region 文件信息
/****************************************************************
*	公司名称：福建力和行智能科技有限公司
*   作    者：Jeff
*   CLR 版本：4.0.30319.42000
*   创建时间：12/20/2024 11:19:05 AM
*	用 户 名：zheqichen 
*   描述说明：
*
*   修改历史：
*		1）	修 改 人：
*			修改日期：
*			修改内容：			
*
*****************************************************************/
#endregion

namespace Lhxzn.LangExtractor
{
    /// <summary>
    /// 类    名:TreeDataGridViewRow
    /// 描    述:
    /// 修改时间:12/20/2024 11:19:05 AM
    /// </summary>
    public class TreeDataGridViewRow: DataGridViewRow
    {
        #region 成员变量

        #region private
        private TreeDataGridViewRow _parent;

        private CheckState _checked = CheckState.Indeterminate;
        private bool _collapse = true;


        #endregion


        #region protected



        #endregion


        #region public
        /// <summary>
        /// 行集合
        /// </summary>
        public TreeDataGridViewRowCollection Rows { get; private set; }

        /// <summary>
        /// 在表格中子行的最后一行索引
        /// </summary>
        public int LastRowIndex
        {
            get
            {
                if (this.Rows.Count == 0)
                {
                    return this.Index;
                }
                else
                {
                    return this.Rows[this.Rows.Count - 1].LastRowIndex;
                }
            }
        }


        /// <summary>
        /// 父行
        /// </summary>
        public TreeDataGridViewRow Parent
        {
            get => _parent;
            internal set => _parent = value;
        }


        public event EventHandler CheckStateChanged;

        /// <summary>
        /// 是否选中
        /// </summary>
        public virtual CheckState Checked
        {
            get => _checked;
            set
            {
                if (_checked != value)
                {
                    _checked = value;
                    CheckStateChanged?.Invoke(this, new EventArgs());
                }

            }
        }

        public bool IsCollapse
        {
            get => _collapse;
            set
            {

                if (this._collapse != value)
                {
                    _collapse = value;
                    if (_collapse)
                    {
                        this.Collapse();
                    }
                    else
                    {
                        this.Expand();
                    }
                }

            }
        }


        /// <summary>
        /// 树状等级
        /// </summary>
        public int Level
        {
            get
            {
                int i = 0;

                TreeDataGridViewRow parent = this.Parent;
                while (parent != null)
                {
                    parent = parent.Parent;
                    i++;
                }
                return i;
            }
        }
        #endregion

        #endregion


        #region 构造函数
        /// <summary>
        /// 函 数 名:构造函数
        /// 函数描述:默认构造函数
        /// 修改时间:12/20/2024 11:19:05 AM
        /// </summary>
        public TreeDataGridViewRow()
        {
            Rows = new TreeDataGridViewRowCollection(this);
            this.Resizable = DataGridViewTriState.False;
        }
        #endregion

        #region 父类函数重载、接口实现

        #endregion

        #region 函数

        #region private



        #endregion


        #region protected



        #endregion


        #region public
        public virtual void Remove()
        {

            foreach (TreeDataGridViewRow row in this.Rows.ToArray())
            {
                row.Remove();
            }
            this.DataGridView.Rows.Remove(this);
            if (this.Parent != null)
            {
                this.Parent.Rows.Remove(this);
            }
        }
        public virtual void ExpandAll()
        {
            Expand(true);
        }

        public virtual void Expand(bool isExpandAll = false)
        {
            this._collapse = false;
            foreach (TreeDataGridViewRow row in this.Rows)
            {
                row.Visible = true;
                if (isExpandAll)
                {
                    row.Expand(true);
                }
            }
        }

        public virtual void Collapse()
        {
            this._collapse = true;
            foreach (TreeDataGridViewRow row in this.Rows)
            {
                row.Visible = false;
                row.Collapse();
            }
        }

        #endregion

        #endregion
    }
}
